#ifndef __tlb_h__
#define __tlb_h__

#include "types.h"

#define N_TLB_ENTRIES  64

// full associated cache
typedef struct tlb_entry_def
{

	__u32 va32;
	__u32 pa32;
	__u32 asid;// by CONTEXTIDR.

	//Supersections consist of 16MB blocks of memory, N = 24
	//Sections consist of 1MB blocks of memory, N = 20
	//Large pages consist of 64KB blocks of memory, N = 16
	//Small pages consist of 4KB blocks of memory, N = 12.
	__u32 blk_size;
	__u32 lockdown:1;
	__u32 pte;

	__u32 nnG:1;
	__u32 valid:1;
	__u32 section:1;
}TLB_ENTRY;

typedef enum tlb_err_code {TLB_HIT,TLB_MISS,FAULT} TLB_ECODE;

class CTLB
{
	TLB_ENTRY tlb[N_TLB_ENTRIES];
	char ages[N_TLB_ENTRIES];
	char last_youngest;

public:
	CTLB() {invlidate_all();}
	//invalidate all unlocked entries in the TLB
	void invlidate_all();
	//invalidate a single TLB entry, by MVA, or MVA and ASID for a non-global entry
	void invlidate_mva(__u32 mva,__u32 asid);
	void invlidate_mva(__u32 mva);
	//invalidate all TLB entries that match a specified ASID.
	void invlidate_asid(__u32 asid);

	TLB_ECODE lookup(__u32 mva,__u32 asid,TLB_ENTRY * p_tlb_entry);
	void update_translation(TLB_ENTRY * p_translation);
	void adj_age(char new_youngest);
};


#endif //__tlb_h__